package com.ptszyxx.popose.module.main.user.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ysg.http.data.CommonRepository;
import com.ptszyxx.popose.common.utils.YBusUtil;
import com.ysg.http.data.entity.user.UserResult;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;

public class UserSetVM extends BaseViewModel<CommonRepository> {
    public String userId;
    public ObservableField<String> dynamicStatus = new ObservableField<>();
    public ObservableField<UserResult> entity = new ObservableField<>();

    public UserSetVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onBlackEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onDynamicCommand = new BindingCommand(o->requestDynamic());
    public BindingCommand onBlackCommand = new BindingCommand(()->uc.onBlackEvent.call());
    public BindingCommand onReportCommand = new BindingCommand(()->{});


    /**
     * 动态
     */
    public void requestDynamic(){
        Map<String, String> map = new HashMap<>();
        map.put("gbuserid", userId);
        Observable observable;
        if (YStringUtil.eq(2, dynamicStatus.get())){
            observable = model.noLookDynamic(map);
        }else{
            observable = model.cancelNoLookDynamic(map);
        }

        HttpUtils.getInstance()
                .data(observable, this,
                        new OnSuccessResult() {
                            @Override
                            public void onSuccessResult(BaseResponse response) {
                                if (YStringUtil.eq(2, dynamicStatus.get())){
                                    dynamicStatus.set("1");
                                }else{
                                    dynamicStatus.set("2");
                                }
                                YBusUtil.setDynamicStatus(dynamicStatus.get());
                            }
                        });
    }

    /**
     * 黑名单
     */
    public void requestBlack(){
        Map<String, String> map = new HashMap<>();
        map.put("lhuserid", userId);
        HttpUtils.getInstance()
                .data(model.blackUser(map), this,
                        new OnSuccessResult() {
                            @Override
                            public void onSuccessResult(BaseResponse response) {
                                YToastUtil.showShort(response.getMsg());
                            }
                        });
    }



}
